package io.itit.ecp.admin.provide.selected;

import io.itit.ecp.admin.server.entity.EnergyCategoryEntity;
import io.itit.ecp.admin.server.service.IEnergyCategoryService;
import io.itit.grass.common.provide.action.resp.SelectedResp;
import io.itit.grass.common.server.selected.ISelected;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;


@Component(value = EnergyCategoryEntitySelected.CODE)
@RequiredArgsConstructor
public class EnergyCategoryEntitySelected implements ISelected<SelectedResp> {

    public static final String CODE = "EnergyCategorySelected";

    private final IEnergyCategoryService energyCategoryService;

    @Override
    public String code() {
        return CODE;
    }

    @Override
    public List<SelectedResp> get(String param) {
        return energyCategoryService.lambdaQuery()
                .orderByAsc(EnergyCategoryEntity::getCategoryName)
                .list()
                .stream()
                .map(t -> SelectedResp.builder()
                        .label(t.getCategoryName())
                        .value(t.getId())
                        .build())
                .collect(Collectors.toList());
    }
}
